//
//  WorksListViewController.m
//  MyMusic
//
//  Created by mac on 2019/4/13.
//  Copyright © 2019 YangYang. All rights reserved.
//

#import "WorksListViewController.h"
#import "WorksListTableViewCell.h"
#import "MusicListViewController.h"
#import "MusicPlayingViewController.h"
#import "AlbumModel.h"
#import "UNZipRARService.h"
#import <AVFoundation/AVFoundation.h>
#import "OtherFileFolderViewController.h"

@interface WorksListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) VLCMediaPlayer *player;


@property (nonatomic, strong) NSString *currentOpenFileTempPath;


@end

@implementation WorksListViewController

- (void)fileNotification:(NSNotification *)notifcation {
    NSDictionary *info = notifcation.userInfo;
    NSString *fileName = [info objectForKey:@"fileName"];
    NSString *filePath = [info objectForKey:@"filePath"];
    
    _currentOpenFileTempPath = filePath;
    
    
    if ([[[fileName pathExtension] lowercaseString] isEqualToString:@"zip"]) {
        if ([self checkFileSize:filePath]) {
            [self unZip:filePath];
        }
        else
        {
            [self showAlertView:filePath];
        }
        
    }
    else if ([[[fileName pathExtension] lowercaseString] isEqualToString:@"rar"])
    {
        
    }
    else
    {
        [self handleOtherProjectFile:fileName filePath:filePath];
    }
}

- (void)showAlertView:(NSString *)filePath
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警报" message:@"文件过大，存储空间不足，无法正常解压文件,即将删除压缩文件！！！" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if ([fileManager fileExistsAtPath:filePath]) {
            if ([fileManager removeItemAtPath:filePath error:nil]) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"文件删除成功！" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
            }
            else
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"文件删除失败！" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
            }
        }
        else
        {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"文件不存在！" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];
    [alertController addAction:confirmAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark - 判断文件大小是否大于设备大小
- (BOOL)checkFileSize:(NSString *)filePath
{
    CGFloat deviceSize = [DeviceDiskSpaceManager getFreeDiskSpace].size;
    CGFloat fileSize = [FileManager getFileSize:filePath].size;
    if (fileSize > deviceSize) {
        return YES;
    }
    else
    {
        return NO;
    }
}

-(void)handleOtherProjectFile:(NSString *)fileName filePath:(NSString *)filePath
{
    NSArray *musicExtensions = @[@"mp3",@"m4a"];
    BOOL isMusic = [musicExtensions containsObject:[[fileName pathExtension] lowercaseString]];
    if (isMusic) {
        NSLog(@"是音乐文件");
        NSString *musicFolder = MusicFolder;
        
        NSFileManager *fileManager = [NSFileManager defaultManager];
        
        if ([fileManager fileExistsAtPath:[musicFolder stringByAppendingPathComponent:[filePath lastPathComponent]]]) {
            NSLog(@"文件已存在，不用再次保存了");
            [self playMusic:fileName filePath:[musicFolder stringByAppendingPathComponent:[filePath lastPathComponent]]];
            NSError *removeFileError = nil;
            if ([fileManager removeItemAtPath:filePath error:&removeFileError]) {
                NSLog(@"源文件删除成功");
            }
            else
            {
                NSLog(@"源文件删除失败：%@",removeFileError);
            }
            return;
        }
        
        if ([fileManager fileExistsAtPath:musicFolder]) {
            NSError * error = nil;
            if ([fileManager moveItemAtPath:filePath toPath:[musicFolder stringByAppendingPathComponent:[filePath lastPathComponent]] error:&error]) {
                NSLog(@"文件已移动至Library目录下成功");
                [self playMusic:fileName filePath:[musicFolder stringByAppendingPathComponent:[filePath lastPathComponent]]];
                [self createMusicListFile:[filePath lastPathComponent]];
            }
            else
            {
                NSLog(@"文件移动至Library目录下失败:%@",error);
            }
        }
        else
        {
            
            static NSInteger count = 0;
            if ([fileManager createDirectoryAtPath:musicFolder withIntermediateDirectories:YES attributes:nil error:nil]) {
                NSLog(@"文件夹创建成功");
                sleep(1.0);
                NSError * error = nil;
                if ([fileManager moveItemAtPath:filePath toPath:[musicFolder stringByAppendingPathComponent:[filePath lastPathComponent]] error:&error]) {
                    
                    NSLog(@"文件已移动至Library目录下成功");
                    
                    [self playMusic:fileName filePath:[musicFolder stringByAppendingPathComponent:[filePath lastPathComponent]]];
                    [self createMusicListFile:[filePath lastPathComponent]];
                }
                else
                {
                    NSLog(@"文件移动至Library目录下失败:%@",error);
                    if (count < 10) {
                        sleep(count * 1.0);
                        [self handleOtherProjectFile:fileName filePath:filePath];
                        count++;
                        NSLog(@"count = %ld",(long)count);
                    }
                }
            }
            else
            {
                NSLog(@"文件夹创建失败");
            }
        }
    }
}

-(void)playMusic:(NSString *)fileName filePath:(NSString *)filePath
{
    AlbumModel *model = [[AlbumModel alloc] init];
    model.songName = [fileName stringByDeletingPathExtension];
    model.songExtensionName = [fileName pathExtension];
    model.songPath = [LibraryFolder stringByAppendingPathComponent:[MusicFolderIdentifier stringByAppendingPathComponent:fileName]];
    model.type = WorksSourceTypeLocal;
    model.downloadFolderName = MusicFolderIdentifier;
    model.albumName = [fileName stringByDeletingPathExtension];
    model.singerName = [fileName stringByDeletingPathExtension];
    model.albumImage = @"album_0.jpg";
    model.singerImage = @"0.jpg";
    model.videoURL = @"";
    
    
    
    MusicPlayingViewController *musicPlayingVC = [MusicPlayingViewController sharedInstance];
    musicPlayingVC.navigationItem.title = model.songName;
    musicPlayingVC.playListModels = @[model];
    musicPlayingVC.currentPlayIndex = 0;
    [musicPlayingVC play:model];
    
    if ([[self getCurrentVC] isKindOfClass:[MusicPlayingViewController class]]) {
        NSLog(@"正在播放界面，无需再次进入");
    }
    else
    {
        [self.navigationController pushViewController:musicPlayingVC animated:YES];
    }
}

-(UIViewController *)getCurrentVC
{
    UIViewController* currentViewController = [self getRootViewController];
    BOOL runLoopFind = YES;
    while (runLoopFind)
    {
        if (currentViewController.presentedViewController)
        {
            currentViewController = currentViewController.presentedViewController;
        }
        else if ([currentViewController isKindOfClass:[UINavigationController class]])
        {
            UINavigationController* navigationController = (UINavigationController* )currentViewController;
            currentViewController = [navigationController.childViewControllers lastObject];
        }
        else if ([currentViewController isKindOfClass:[UITabBarController class]])
        {
            UITabBarController* tabBarController = (UITabBarController* )currentViewController;
            currentViewController = tabBarController.selectedViewController;
        }
        else
        {
            NSUInteger childViewControllerCount = currentViewController.childViewControllers.count;
            if (childViewControllerCount > 0)
            {
                currentViewController = currentViewController.childViewControllers.lastObject;
                return currentViewController;
            }
            else
            {
                return currentViewController;
            }
        }
    }
    return currentViewController;
}

- (UIViewController *)getRootViewController{
    UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
    NSAssert(window, @"The window is empty");
    return window.rootViewController;
}

-(void)createMusicListFile:(NSString *)fileName
{
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:OtherOpenFilePath]) {
        NSMutableArray *otherOpenFileArr = [NSMutableArray arrayWithContentsOfFile:OtherOpenFilePath];
        
        NSMutableArray *otherMusics = [NSMutableArray new];
        NSMutableDictionary *otherMusicDic = [NSMutableDictionary new];
        
        for (id object in otherOpenFileArr) {
            if ([object isKindOfClass:[NSDictionary class]]) {
                NSDictionary *musicDic = (NSDictionary *)object;
                if ([musicDic[@"folderName"] isEqualToString:MusicIdentifier]) {
                    otherMusicDic = [NSMutableDictionary dictionaryWithDictionary:musicDic];
                    NSArray *otherMusic = musicDic[@"folders"];
                    [otherMusics addObjectsFromArray:otherMusic];
                    NSLog(@"已经打开过其他音乐文件！");
                    break;
                }
                
            }
        }
        
        
        
        for (NSDictionary *musicDic in otherMusics) {
            if ([musicDic[@"musicFullName"] isEqualToString:fileName]) {
                NSLog(@"文件记录已存在，无需再次保存");
                return;
            }
        }
        
        for (id object in otherOpenFileArr) {
            if ([object isKindOfClass:[NSDictionary class]]) {
                NSDictionary *musicDic = (NSDictionary *)object;
                if ([musicDic[@"folderName"] isEqualToString:MusicIdentifier]) {
                    [otherOpenFileArr removeObject:musicDic];
                    NSLog(@"移除文件");
                    break;
                }
                
            }
        }
        
        NSMutableDictionary *musicDic = [NSMutableDictionary new];
        musicDic[@"musicName"] = [fileName stringByDeletingPathExtension];
        musicDic[@"extensionName"] = [fileName pathExtension];
        musicDic[@"musicFullName"] = fileName;
        musicDic[@"songPath"] = [MusicFolderIdentifier stringByAppendingPathComponent:fileName];
        musicDic[@"albumImage"] = @"album_0.jpg";
        musicDic[@"albumName"] = [fileName stringByDeletingPathExtension];
        musicDic[@"singerImage"] = @"0.jpg";
        musicDic[@"singerName"] = [fileName stringByDeletingPathExtension];
        musicDic[@"videoURL"] = fileName;
        musicDic[@"writer"] = [fileName stringByDeletingPathExtension];
        [otherMusics addObject:musicDic];
        
        otherMusicDic[@"folders"] = otherMusics;
        otherMusicDic[@"folderName"] = MusicIdentifier;
        [otherOpenFileArr addObject:otherMusicDic];
        if ([otherOpenFileArr writeToFile:OtherOpenFilePath atomically:YES]) {
            NSLog(@"文件保存成功");
        }
        else
        {
            NSLog(@"文件保存失败");
        }
        
    }
    else
    {
        NSMutableArray *otherOpenFileArr = [NSMutableArray new];
        NSMutableDictionary *otherMusicDic = [NSMutableDictionary new];
        otherMusicDic[@"folderName"] = MusicIdentifier;
        NSMutableArray *musicArr = [NSMutableArray new];
        NSMutableDictionary *musicDic = [NSMutableDictionary new];
        musicDic[@"musicName"] = [fileName stringByDeletingPathExtension];
        musicDic[@"extensionName"] = [fileName pathExtension];
        musicDic[@"musicFullName"] = fileName;
        musicDic[@"songPath"] = [MusicFolderIdentifier stringByAppendingPathComponent:fileName];
        musicDic[@"albumImage"] = @"album_0.jpg";
        musicDic[@"albumName"] = [fileName stringByDeletingPathExtension];
        musicDic[@"singerImage"] = @"0.jpg";
        musicDic[@"singerName"] = [fileName stringByDeletingPathExtension];
        musicDic[@"videoURL"] = fileName;
        musicDic[@"writer"] = [fileName stringByDeletingPathExtension];
        [musicArr addObject:musicDic];
        otherMusicDic[@"folders"] = musicArr;
        
        [otherOpenFileArr addObject:otherMusicDic];
        if ([otherOpenFileArr writeToFile:OtherOpenFilePath atomically:YES]) {
            NSLog(@"文件保存成功");
        }
        else
        {
            NSLog(@"文件保存失败");
        }
    }
    [self initDataSource];
}



#pragma mark -------------- zip解压缩 --------------
- (void)unZip:(NSString *)zipFilePath{
    NSLog(@"开始解压文件");
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    
    
    NSString *destPath = [self applicationDocumentsDirectory];
    [self unArchive:zipFilePath andPassword:nil destinationPath:destPath];
    
}

- (NSString *)applicationDocumentsDirectory
{
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    basePath = [basePath stringByAppendingPathComponent:@"OpenOtherFile"];
    return basePath;
}


- (void)unArchive: (NSString *)filePath andPassword:(NSString*)password destinationPath:(NSString *)destPath{
    NSAssert(filePath, @"can't find filePath");
    UNZipRARService *unarchive = [[UNZipRARService alloc]initWithPath:filePath];
    if (password != nil && password.length > 0) {
        unarchive.password = password;
    }
    __weak typeof(self) weakSelf = self;
    if (destPath != nil)
        
        unarchive.destinationPath = destPath;//(Optional). If it is not given, then the file is unarchived in the same location of its archive/file.
    
    unarchive.downLoadFilePathBlock = ^(NSString *filePath){
        //zip取
        NSLog(@"%@",filePath);
        
        [self removeItemWithFolder:weakSelf.currentOpenFileTempPath];
        
        OtherFileFolderViewController *otherFileFolderVC = [[OtherFileFolderViewController alloc] init];
        otherFileFolderVC.navigationItem.title = @"OpenOtherFile";
        
        otherFileFolderVC.folderPath = @"OpenOtherFile";
        BackItemView
        otherFileFolderVC.folderName = @"OpenOtherFile";
        [weakSelf.navigationController pushViewController:otherFileFolderVC animated:YES];
        [SVProgressHUD dismiss];
        NSLog(@"文件解压完成【解压成功】");
    };
    unarchive.completionBlock = ^(NSArray *filePaths){
        //rar取
        NSLog(@"For Archive : %@",filePath);
        for (NSString *filename in filePaths) {
            NSLog(@"Extracted Filepath: %@", filename);
        }
    };
    unarchive.failureBlock = ^(){
        NSLog(@"Cannot be unarchived");
        NSLog(@"文件解压失败");
        [SVProgressHUD dismiss];
    };
    [unarchive decompress];
}

-(void)removeItemWithFolder:(NSString *)folder
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager removeItemAtPath:folder error:nil]) {
        NSLog(@"文件删除成功");
    }
    else
    {
        NSLog(@"文件删除失败");
    }
}

- (void)changeMusicListNotification:(NSNotification *)notification
{
//    NSDictionary *userInfo = notification.userInfo;
//    NSLog(@"userInfo = %@",userInfo);
    [self initDataSource];
}

//-(void)addSongList:(NSNotification *)notification
//{
//    NSDictionary *userInfo = notification.userInfo;
//    NSLog(@"userInfo = %@",userInfo);
//
//    WorksPathModel *model = [[WorksPathModel alloc] init];
//    model.worksName = userInfo[@"folderName"];
//    model.worksPath = @"";
//    model.type = WorksSourceTypeLocal;
//    model.downloadSongFileFolderPath = userInfo[@"downloadSongFileFolderPath"];
//    model.localSongs = userInfo[@"folders"];
//    [self.dataSource addObject:model];
//
//    NSLog(@"[NSThread currentThread] = %@",[NSThread currentThread]);
//
//    [self.tableView reloadData];
//}

//-(void)addSongItemIntoListNotification:(NSNotification *)notification
//{
//    NSDictionary *userInfo = notification.userInfo;
//    NSLog(@"userInfo = %@",userInfo);
//}

//-(void)removeItemMethod:(NSNotification *)notification
//{
//    NSDictionary *userInfo = notification.userInfo;
//    NSLog(@"userInfo = %@",userInfo);
//    NSString *songName = userInfo[@"songName"];
//
//
//    NSMutableArray *songArr = [NSMutableArray new];
//    [songArr addObjectsFromArray:self.dataSource];
//
//    for (WorksPathModel *model in songArr) {
//        if ([model.worksName isEqualToString:songName]) {
//            [self.dataSource removeObject:model];
//        }
//    }
//    [self.tableView reloadData];
//
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"万能播放器";
    
//    NSString *videoUrlString = [[NSBundle mainBundle] pathForResource:@"Video_1.mp4" ofType:@""];
//    NSLog(@"videoUrlString = %@",videoUrlString);
//    NSURL *videoUrl = [NSURL fileURLWithPath:videoUrlString];
//    
//    UIImage *videoImage = [SystemTools getVideoPreViewImage:videoUrl];
//    CGSize size = videoImage.size;
//    NSLog(@"size = %@",NSStringFromCGSize(size));
    
    
    
    
    
    //用其他软件打开 传进来的文件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileNotification:) name:OpenFileNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeMusicListNotification:) name:ChangeMusicListNotification object:nil];
    
    PlayerBottomView *bottomView = [PlayerBottomView shareInstance];
    UIWindow *windows = [[UIApplication sharedApplication] keyWindow];
    [windows addSubview:bottomView];
    bottomView.frame = CGRectMake(0, kScreenHeight - 100, kScreenWidth, 100);
    bottomView.backgroundColor = [UIColor whiteColor];
    __weak typeof(self) weakSelf = self;
    bottomView.ClickViewBlock = ^(PlayerBottomView * _Nonnull bottomView) {
        NSLog(@"相应点击事件");
        MusicPlayingViewController *playingVC = [MusicPlayingViewController sharedInstance];
        if ([playingVC isPlaying]) {
            NSLog(@"正在播放音乐");
        }
        else
        {
            NSLog(@"未处于播放状态");
            playingVC.currentPlayIndex = bottomView.currentPlayingIndex;
            playingVC.playListModels = bottomView.playingModelList;
            [playingVC play:bottomView.model];
            [playingVC playingToLength:bottomView.model.currentDuration];
        }
        [weakSelf.navigationController pushViewController:playingVC animated:YES];
    };
    NSDictionary *currentPlayingMusicDic = [NSDictionary dictionaryWithContentsOfFile:CurrentPlayingMusicPath];
    if (currentPlayingMusicDic) {
        CurrentPlayingMusicModel *currentPlayingModel = [CurrentPlayingMusicModel mj_objectWithKeyValues:currentPlayingMusicDic];
        bottomView.currentPlayingIndex = currentPlayingModel.playingIndex;
        bottomView.playingModelList = [AlbumModel mj_objectArrayWithKeyValuesArray:currentPlayingModel.playingList];
        bottomView.model = bottomView.playingModelList[bottomView.currentPlayingIndex];
        bottomView.model.currentDuration = currentPlayingModel.currentDuration;
        bottomView.progress = currentPlayingModel.progress;
    }
    else
    {
        NSLog(@"当前无正在播放的歌曲");
    }
    
    
    [self initTableView];
    [self initDataSource];
}

-(void)initDataSource
{
    [self.dataSource removeAllObjects];
    NSArray *pathArr = [[NSBundle mainBundle] pathsForResourcesOfType:@"plist" inDirectory:@"NetSource"];
    NSMutableArray *netFileList = [NSMutableArray new];
    for (NSString *path in pathArr) {
        NSString *name = [[path stringByDeletingPathExtension] lastPathComponent];
        NSString *fullName = [path lastPathComponent];
        NSMutableDictionary *pathNameDic = [NSMutableDictionary new];
        pathNameDic[@"worksName"] = name;
        pathNameDic[@"worksPath"] = fullName;
        pathNameDic[@"sourceType"] = [NSNumber numberWithInteger:WorksSourceTypeNet];
        [netFileList addObject:pathNameDic];
    }
    NSArray *sortArr = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"worksName" ascending:YES]];
    [netFileList sortUsingDescriptors:sortArr];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:OtherOpenFilePath]) {
        NSArray *localSongArr = [NSArray arrayWithContentsOfFile:OtherOpenFilePath];
        for (NSDictionary *dic in localSongArr) {
            if ([dic isKindOfClass:[NSDictionary class]]) {
                WorksPathModel *model = [[WorksPathModel alloc] init];
                model.worksName = dic[@"folderName"];
                model.worksPath = @"";
                model.type = WorksSourceTypeLocal;
                model.localSongs = dic[@"folders"];
                if (model.localSongs.count > 0) {
                    NSDictionary *dic = [model.localSongs firstObject];
                    model.downloadSongFileFolderPath = [dic[@"songPath"] stringByDeletingLastPathComponent];
                    
                }
                [self.dataSource addObject:model];
            }
            
        }
    }
    
    
    
    NSMutableArray *worksTempList = [NSMutableArray new];
    [worksTempList addObjectsFromArray:netFileList];
    NSArray *worksList = [NSArray arrayWithArray:worksTempList];
    
    for (NSDictionary *dic in worksList) {
        WorksPathModel *model = [[WorksPathModel alloc] init];
        model.worksName = dic[@"worksName"];
        model.worksPath = dic[@"worksPath"];
        model.type = [dic[@"sourceType"] integerValue];
        model.downloadSongFileFolderPath = [NSString stringWithFormat:@"%@/song",model.worksName];
        [self.dataSource addObject:model];
    }
    [self.tableView reloadData];
}

-(void)initTableView
{
    PlayerBottomView *bottomView = [PlayerBottomView shareInstance];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - CGRectGetHeight(bottomView.frame)) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[WorksListTableViewCell class] forCellReuseIdentifier:@"WorksListTableViewCell"];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WorksListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WorksListTableViewCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    WorksPathModel *model = self.dataSource[indexPath.row];
    cell.model = model;
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MusicListViewController *musicListVC = [[MusicListViewController alloc] init];
    WorksPathModel *model = self.dataSource[indexPath.row];
    musicListVC.navigationItem.title = model.worksName;
    musicListVC.worksPathModel = model;
    BackItemView
    [self.navigationController pushViewController:musicListVC animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = [NSMutableArray new];
    }
    return _dataSource;
}

//-(void)createTeGongHuangFeiChuQiaoZhuan_YiNiDuoDuoSource
//{
//
//    NSMutableArray *musicArr = [NSMutableArray new];
//
//    for (NSInteger i = 1; i < 51; ++i) {
////
//
//
//        NSMutableDictionary *musicDic = [NSMutableDictionary new];
//        NSString *urlString = [NSString stringWithFormat:@"https://pp.ting55.com/201905060258/9daf9981a03bcd39052de72c9ef9026c/2018/08/12706/%ld.mp3",i];
//        https://pp.ting55.com/201905060308/809ae3b08adb64f09e2918454477bfcb/2018/08/12706/50.mp3
//        musicDic[@"musicName"] = [NSString stringWithFormat:@"妙偶天成_%.3ld",i];
//        musicDic[@"extensionName"] = [urlString pathExtension];
//        musicDic[@"musicFullName"] = [NSString stringWithFormat:@"%@.%@",musicDic[@"musicName"],musicDic[@"extensionName"]];
//        musicDic[@"songPath"] = urlString;
//        musicDic[@"albumName"] = @"妙偶天成_一月";
//        musicDic[@"singerName"] = @"一月";
//        musicDic[@"writer"] = @"冬天的柳叶";
//        musicDic[@"videoURL"] = @"";
//        musicDic[@"albumImage"] = [NSString stringWithFormat:@"album_%ld.jpg",(i % 4)];
//        musicDic[@"singerImage"] = [NSString stringWithFormat:@"%ld.jpg",(i % 4)];
//        [musicArr addObject:musicDic];
//
//
//    }
//
//    NSString *bj_xr = DownloadFilePath(@"妙偶天成_一月.plist");
//    NSLog(@"cqz = %@",bj_xr);
//    [musicArr writeToFile:bj_xr atomically:YES];
//
//
//
////    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"花千骨_筱梦、布兰德.plist" ofType:@""];
////    NSArray *sourceArr = [NSArray arrayWithContentsOfFile:filePath];
////    NSMutableArray *musicArr = [NSMutableArray new];
////
////    for (NSInteger i = 1; i < sourceArr.count + 1; i++) {
////        NSMutableDictionary *musicDic = [NSMutableDictionary dictionaryWithDictionary:sourceArr[i - 1]];
////        musicDic[@"musicName"] = [NSString stringWithFormat:@"花千骨_%.3ld",i];
////        musicDic[@"musicFullName"] = [NSString stringWithFormat:@"%@.%@",musicDic[@"musicName"],musicDic[@"extensionName"]];
////        [musicArr addObject:musicDic];
////    }
////    NSLog(@"musicArr = %@",musicArr);
////    NSString *bj_xr = DownloadFilePath(@"cqz.plist");
////    NSLog(@"cqz = %@",bj_xr);
////    [musicArr writeToFile:bj_xr atomically:YES];
//
//
//
//
//
//
////    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"错妃诱情_陌上轻寒_temp.plist" ofType:@""];
////    NSArray *sourceArr = [NSArray arrayWithContentsOfFile:filePath];
////    NSMutableArray *musicArr = [NSMutableArray new];
////
////    for (NSInteger i = 1; i < sourceArr.count + 1; i++) {
////        NSMutableDictionary *musicDic = [NSMutableDictionary new];
////        NSString *urlString = sourceArr[i - 1];
////        musicDic[@"musicName"] = [NSString stringWithFormat:@"错妃诱情_%.3ld",i];
////        musicDic[@"extensionName"] = [urlString pathExtension];
////        musicDic[@"musicFullName"] = [NSString stringWithFormat:@"%@.%@",musicDic[@"musicName"],musicDic[@"extensionName"]];
////        musicDic[@"songPath"] = urlString;
////        musicDic[@"albumName"] = @"错妃诱情_陌上轻寒";
////        musicDic[@"singerName"] = @"陌上轻寒";
////        musicDic[@"writer"] = @"月出云";
////        musicDic[@"albumImage"] = [NSString stringWithFormat:@"album_%ld.jpg",(i % 4)];
////        musicDic[@"singerImage"] = [NSString stringWithFormat:@"%ld.jpg",(i % 4)];
////        [musicArr addObject:musicDic];
////    }
////    NSLog(@"musicArr = %@",musicArr);
////    NSString *bj_xr = DownloadFilePath(@"错妃诱情_陌上轻寒.plist");
////    NSLog(@"cqz = %@",bj_xr);
////    [musicArr writeToFile:bj_xr atomically:YES];
//
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
